package com.larsgard.gedviewer.server.storage.entities;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.larsgard.gedviewer.shared.entities.Person;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class JDOPerson implements PersitenceCapable, Serializable {

    private static final long serialVersionUID = 7864405294070917717L;
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String idno;
    @Persistent
    private String sex;
    @Persistent
    private String givenName;
    @Persistent
    private String familyName;
    @Persistent
    private String birthplace;
    @Persistent
    private String birthDate;
    @Persistent
    private String deathDate;
    @Persistent
    private String deathPlace;
    @Persistent
    private String motherIdno;
    @Persistent
    private String fatherIdno;
    @Persistent
    private String treeId;

    public void setIdno(String idno) {
	this.idno = idno;
    }

    public String getIdno() {
	return idno;
    }

    public void setFamilyName(String familyName) {
	this.familyName = familyName;
    }

    public String getFamilyName() {
	return familyName;
    }

    public void setGivenName(String givenName) {
	this.givenName = givenName;
    }

    public String getGivenName() {
	return givenName;
    }

    public void setSex(String sex) {
	this.sex = sex;
    }

    public String getSex() {
	return sex;
    }

    public String getBirthPlace() {
	return getBirthplace();
    }

    public String getBirthDate() {
	return birthDate;
    }

    public String getDeathDate() {
	return deathDate;
    }

    public String getDeathPlace() {
	return deathPlace;
    }

    public String getMotherIdno() {
	return motherIdno;
    }

    public String getFatherIdno() {
	return fatherIdno;
    }

    public void setBirthplace(String birthplace) {
	this.birthplace = birthplace;
    }

    public String getBirthplace() {
	return birthplace;
    }

    public void setBirthDate(String birthDate) {
	this.birthDate = birthDate;
    }

    public void setDeathDate(String deathDate) {
	this.deathDate = deathDate;
    }

    public void setDeathPlace(String deathPlace) {
	this.deathPlace = deathPlace;
    }

    public void setMotherIdno(String motherIdno) {
	this.motherIdno = motherIdno;
    }

    public void setFatherIdno(String fatherIdno) {
	this.fatherIdno = fatherIdno;
    }

    @Override
    public String toString() {
	return givenName + " " + familyName;
    }

    public void setTreeId(String treeId) {
	this.treeId = treeId;
    }

    public String getTreeId() {
	return treeId;
    }

    public Key getKey() {
	return key;
    }

    public void setKey(Key key) {
	this.key = key;
    }

    public Person getPerson() {
	Person person = new Person();
	person.setGivenName(givenName);
	person.setFamilyName(familyName);
	person.setSex(sex);
	person.setBirthDate(birthDate);
	person.setBirthplace(birthplace);
	person.setDeathDate(deathDate);
	person.setDeathPlace(deathPlace);
	person.setMotherIdno(motherIdno);
	person.setFatherIdno(fatherIdno);
	person.setIdno(idno);

	return person;
    }

}
